package com.ellecity06.cwhiskymall.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.common.ktx.load
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.response.SearchDiscoveryResponse
import com.ellecity06.cwhiskymall.databinding.ItemHotSearchBinding

/**
 * @author ellecity06
 * @time 2024/11/1 18:49
 * @des 热门搜索顶部
 */
class SearchHotAdapter : BaseAdapter<SearchDiscoveryResponse.HotSearchSpuVo, ItemHotSearchBinding>() {
    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemHotSearchBinding {
        return ItemHotSearchBinding.inflate(layoutInflater, parent, false)
    }

    override fun convert(
        binding: ItemHotSearchBinding,
        position: Int,
        item: SearchDiscoveryResponse.HotSearchSpuVo
    ) {
        binding.tvGoodName.text = item.spuName
        binding.tvSaleCount.text = item.spuTitle
        binding.ivGood.load(context, item.mainImage)
        binding.tvNum.text = "${position + 4}"
        when (item.labelType) {
            1 -> {
                binding.ivBadge.visibility = View.VISIBLE
                binding.ivBadge.setImageResource(R.mipmap.icon_badge_good_hot)
            }

            2 -> {
                binding.ivBadge.visibility = View.VISIBLE
                binding.ivBadge.setImageResource(R.mipmap.icon_badge_good_new)
            }

            else -> {
                binding.ivBadge.visibility = View.GONE
            }
        }
    }
}